package com.li.injection;

import com.li.entity.Student;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * @author LiDong
 * @version 1.0.0
 * @className BeanInjection.java
 * @createTime 2021年09月04日 21:00:00
 */
public class BeanInjectionTest {

    private static final Logger logger = LoggerFactory.getLogger(BeanInjectionTest.class);

    @Test
    public void test1() {
        ClassPathResource resource = new ClassPathResource("StudentBean.xml");
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        reader.loadBeanDefinitions(resource);

        Student student = factory.getBean(Student.class);
        logger.info("当前 Stundet :{}", student);
    }

    @Test
    public void test2() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("StundetBeanOne.xml");
        Student bean = applicationContext.getBean(Student.class);
        logger.info("当前 Student :{}", bean);
    }


}
